package repository;

import Dto.NewsTbEntity;
import Dto.UserTbEntity;
import dbConnect.dbConnecter;

import java.sql.ResultSet;
import java.sql.SQLException;

public class FindNewsRepository{
    public FindNewsRepository(){

    }

    public boolean FindNews_Head(String headline,NewsTbEntity newsTbEntity)  throws SQLException {


        dbConnecter Con = new dbConnecter();
        Con.getConnection();
        String sql = "select * from news where Head="+dbConnecter.toSql(headline);
        try {
            ResultSet resultSet = Con.querySql(sql);
            while(resultSet.next()) {
                newsTbEntity.setNewsId(resultSet.getInt(1));
                newsTbEntity.setNewsHeadline(resultSet.getString(2));
                newsTbEntity.setNewsName(resultSet.getString(3));
                newsTbEntity.setNewsContent(resultSet.getString(4));
                newsTbEntity.setUpTime(resultSet.getString(5));
                return true;
            }
            return false;
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return false;
        }
        finally {
            Con.close();
        }
    }

}
